<?php

/**
 *      [CodeJm!] Author CodeJm[codejm@163.com].
 *
 *      
 *      $Id: Surcharge.php 2016-03-31 15:42:44 codejm $
 */

class SurchargeModel extends \Core_CMode {

    public $_table = '`yaf_surcharge`';

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'scg_id' => 'id', 
            'scg_name' => '名称', 
            'scg_price' => '价格', 
            'unit' => '单位', 
            'desciption' => '描述', 
            'type' => '0表示其他，1表示出发楼层，2表示到达楼层', 
            'addtime' => '添加时间',
        );
    }

    /**
     * 楠岃瘉瑙勫垯
     *
     */
    public function rules() {
        return array(
            'default'=> array(
                array('scg_name', 'required|maxlength[30]'),
                array('scg_price', 'required|maxlength[6]'),
                array('unit', 'required|maxlength[10]'),
                array('desciption', 'required'),
                array('type', 'maxlength[1]|integer'),
                array('addtime', 'required|maxlength[20]'),

            ),
        );
    }

    /**
     * 鎵归噺鍒犻櫎
     *
     */
    public function delSurcharges($ids) {
        $ids_str = implode(',', array_fill(0, count($ids), '?'));
        $where = 'scg_id IN ('.$ids_str.')';
        return $this->update($where, array('status'=>-1), $ids);
    }
    
    public function insertAll($data){
        if(!empty($data)){
            
            $keys = array_keys($data[0]);
            $fields = '`'.implode('`, `',$keys).'`';
            $sql = 'INSERT INTO '.$this->_table.'('.$fields.') VALUES ';
            $line = '';
            foreach($data as $v ){
                if(empty($repeat[$v['id']])){
                    $values = implode("','",$v);
                    $line .='(\''.$values.'\'),';
                }
            }

            if(!empty($line)){
                $sql .= trim($line,',');
                //清除表数据
                $this->db->exec('TRUNCATE '.$this->_table);
                return $this->db->exec($sql);

            }

        }else{
            return false;
        }
    }
}

?>
